package com.notion.algorithms.datastructures.graph;

import java.util.Arrays;

public class Graph {
	private Vertex[] vertices;
	public Graph(int noOfVertices){
		vertices = new Vertex[noOfVertices];
		initVertices();
	}
	public Graph(Vertex[] vertices){
		//defensive copy for immutability
		this.vertices=Arrays.copyOf(vertices,vertices.length);
	}
	private void initVertices() {
		for(int i=1;i<=vertices.length;i++){
			vertices[i-1]=new Vertex(i);
		}
	}
	
	public void addEdgeBetweenVertexNumber(int vNo1, int vNo2,int cost){
		Vertex vertex1 = vertices[vNo1-1];
		Vertex vertex2 = vertices[vNo2-1];
		Edge e = new Edge(vertex1, vertex2, cost);
		vertex1.addEdge(e);
		vertex2.addEdge(e);				
	}
	
	public Vertex[] getVertices(){
		return Arrays.copyOf(vertices, vertices.length);
	}
}
